﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARS.Control.Custom.Entity.Widget;

namespace ARS.Control.Custom.Entity.Fields
{
    public class DateTimeAutoField:HiddenInputField
    {
        public DateTimeAutoField():base()
        {
            this.IsAllowUpdate = false;
        }

        private bool _Auto_Now=false;
        /// <summary>
        /// 提交时更新时间
        /// </summary>
        public bool Auto_Now
        {
            get
            {
                return this._Auto_Now;
            }
            set
            {
                if (value == true)
                {
                    base.IsAllowUpdate = true;
                }
                else
                {
                    base.IsAllowUpdate = false;
                }
                this._Auto_Now = value;
            }
        }
        /// <summary>
        /// 添加时保存时间
        /// </summary>
        public bool Auto_Now_Add
        {
            get;
            set;
        }

        public override void InitInputValue(EntityBaseControl entityBaseControl)
        {
            //DateTimeAutoField field = control as DateTimeAutoField;
            if (this.Auto_Now)
            {
                this.Value = DateTime.Now;
            }
            else if (this.Auto_Now_Add)
            {
                if (entityBaseControl.IsAdd)
                {
                    this.Value = DateTime.Now;
                }
            }
            //return null;
        }
    }
}
